]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Add scaffolding for the new screenshot UI
authorIvan Molodetskikh <yalterz@gmail.com>
Mon, 16 Aug 2021 07:16:19 +0000 (10:16 +0300)
committerMarge Bot <marge-bot@gnome.org>
Thu, 27 Jan 2022 22:25:42 +0000 (22:25 +0000)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1954>

data/org.gnome.shell.gschema.xml.in
js/ui/layout.js
js/ui/main.js
js/ui/screenshot.js

index a6b2f5a1f0470c1335b07c674f8a0a277e3d8d47..1dadb13c280bf0a555c2335765cabaa3d398ae77 100644 (file)
       <default>["&lt;Super&gt;9"]</default>
       <summary>Switch to application 9</summary>
     </key>
+    <key name="show-screenshot-ui" type="as">
+      <default>["Print"]</default>
+      <summary>Show screenshot UI</summary>
+    </key>
   </schema>
 
   <schema id="org.gnome.shell.app-switcher"
index ccdde71c7f51c3fe4f50ecb2353bf27dd5ea2e58..102bed041ef6d2ccb72486c60719ddff344a2ff0 100644 (file)
@@ -256,6 +256,12 @@ var LayoutManager = GObject.registerClass({
         this.addTopChrome(this.keyboardBox);
         this._keyboardHeightNotifyId = 0;
 
+        this.screenshotUIGroup = new St.Widget({
+            name: 'screenshotUIGroup',
+            layout_manager: new Clutter.BinLayout(),
+        });
+        this.addTopChrome(this.screenshotUIGroup);
+
         // A dummy actor that tracks the mouse or text cursor, based on the
         // position and size set in setDummyCursorGeometry.
         this.dummyCursor = new St.Widget({ width: 0, height: 0, opacity: 0 });
index 19735ccc0ef0bd0702ce8405e93017ae564bc430..ecb7a980f49a48f521c7bb18f0f935a45f836bb8 100644 (file)
@@ -6,7 +6,7 @@
             screenSaverDBus, uiGroup, magnifier, xdndHandler, keyboard,
             kbdA11yDialog, introspectService, start, pushModal, popModal,
             activateWindow, createLookingGlass, initializeDeferredWork,
-            getThemeStylesheet, setThemeStylesheet */
+            getThemeStylesheet, setThemeStylesheet, screenshotUI */
 
 const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
 
@@ -35,6 +35,7 @@ const LoginManager = imports.misc.loginManager;
 const LookingGlass = imports.ui.lookingGlass;
 const NotificationDaemon = imports.ui.notificationDaemon;
 const WindowAttentionHandler = imports.ui.windowAttentionHandler;
+const Screenshot = imports.ui.screenshot;
 const ScreenShield = imports.ui.screenShield;
 const Scripting = imports.ui.scripting;
 const SessionMode = imports.ui.sessionMode;
@@ -74,6 +75,7 @@ var padOsdService = null;
 var osdWindowManager = null;
 var osdMonitorLabeler = null;
 var sessionMode = null;
+var screenshotUI = null;
 var shellAccessDialogDBusService = null;
 var shellAudioSelectionDBusService = null;
 var shellDBusService = null;
@@ -224,6 +226,8 @@ function _initializeUI() {
     windowAttentionHandler = new WindowAttentionHandler.WindowAttentionHandler();
     componentManager = new Components.ComponentManager();
 
+    screenshotUI = new Screenshot.ScreenshotUI();
+
     introspectService = new Introspect.IntrospectService();
 
     layoutManager.init();
index 97fcfacd015ec6434e075d2734fe96577ae5bb6c..abc4a325439402a9026036cfe13e99336fbb16b3 100644 (file)
@@ -1,5 +1,5 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported ScreenshotService */
+/* exported ScreenshotService, ScreenshotUI, showScreenshotUI */
 
 const { Clutter, Gio, GObject, GLib, Meta, Shell, St } = imports.gi;
 
@@ -19,6 +19,97 @@ const { DBusSenderChecker } = imports.misc.util;
 
 const ScreenshotIface = loadInterfaceXML('org.gnome.Shell.Screenshot');
 
+var ScreenshotUI = GObject.registerClass(
+class ScreenshotUI extends St.Widget {
+    _init() {
+        super._init({
+            name: 'screenshot-ui',
+            constraints: new Clutter.BindConstraint({
+                source: global.stage,
+                coordinate: Clutter.BindCoordinate.ALL,
+            }),
+            layout_manager: new Clutter.BinLayout(),
+            opacity: 0,
+            visible: false,
+        });
+
+        Main.layoutManager.screenshotUIGroup.add_child(this);
+
+        this._grabHelper = new GrabHelper.GrabHelper(this, {
+            actionMode: Shell.ActionMode.POPUP,
+        });
+
+        Main.layoutManager.connect('monitors-changed', () => {
+            // Nope, not dealing with monitor changes.
+            this.close(true);
+        });
+
+        Main.wm.addKeybinding(
+            'show-screenshot-ui',
+            new Gio.Settings({ schema_id: 'org.gnome.shell.keybindings' }),
+            Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
+            Shell.ActionMode.NORMAL |
+            Shell.ActionMode.OVERVIEW |
+            Shell.ActionMode.SYSTEM_MODAL |
+            Shell.ActionMode.LOOKING_GLASS |
+            Shell.ActionMode.POPUP,
+            showScreenshotUI
+        );
+    }
+
+    open() {
+        // Get rid of any popup menus.
+        // We already have them captured on the screenshot anyway.
+        //
+        // This needs to happen before the grab below as closing menus will
+        // pop their grabs.
+        Main.layoutManager.emit('system-modal-opened');
+
+        const grabResult = this._grabHelper.grab({
+            actor: this,
+            onUngrab: () => this.close(),
+        });
+        if (!grabResult)
+            return;
+
+        this.remove_all_transitions();
+        this.visible = true;
+        this.ease({
+            opacity: 255,
+            duration: 200,
+            mode: Clutter.AnimationMode.EASE_OUT_QUAD,
+        });
+    }
+
+    _finishClosing() {
+        this.hide();
+    }
+
+    close(instantly = false) {
+        this._grabHelper.ungrab();
+
+        if (instantly) {
+            this._finishClosing();
+            return;
+        }
+
+        this.remove_all_transitions();
+        this.ease({
+            opacity: 0,
+            duration: 200,
+            mode: Clutter.AnimationMode.EASE_OUT_QUAD,
+            onComplete: this._finishClosing.bind(this),
+        });
+    }
+});
+
+/**
+ * Shows the screenshot UI.
+ */
+function showScreenshotUI() {
+    Main.screenshotUI.open();
+}
+
 var ScreenshotService = class {
     constructor() {
         this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ScreenshotIface, this);